package com.esoon.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;

import com.esoon.smartsee.MainActivity;
import com.esoon.smartsee.R;
import com.esoon.utils.AlertDialogCommon;

import java.io.File;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class FaceFailActivity extends AppCompatActivity {
    private AlertDialogCommon recognizeDialog;
    @BindView(R.id.faceImg)
    ImageView imageView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_face_fail);


        initView();


    }

    private void initView() {

        ButterKnife.bind(this);
        File file = new File(Environment.getExternalStorageDirectory() + "/temp.jpg");
        if (file.exists()) {
            imageView.setImageURI(Uri.fromFile(file));
        }
        showRecognizeFailDialog();
    }

    private void showRecognizeFailDialog() {

        recognizeDialog = new AlertDialogCommon(FaceFailActivity.this, R.layout.face_fail_dialog);
        recognizeDialog.showDialog();
        WindowManager ctim = getWindowManager();
        Display ctid = ctim.getDefaultDisplay(); //为获取屏幕宽、高
        WindowManager.LayoutParams ctip = recognizeDialog.getWindow().getAttributes();//获取对话框当前的参数值
        ctip.height = ctid.getHeight() * 1; //高度设置为屏幕宽度
        ctip.width = ctid.getWidth() * 1; //宽度设置为屏幕长度
        recognizeDialog.getWindow().setAttributes(ctip); //设置生效
        Window ctidialogWindow = recognizeDialog.getWindow();
        WindowManager.LayoutParams ctilp = ctidialogWindow.getAttributes();

        Button reRecognize = recognizeDialog.getView().findViewById(R.id.reRecognize);
        Button exit = recognizeDialog.getView().findViewById(R.id.exitButton);
        reRecognize.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(FaceFailActivity.this, FaceRecognizeActivity.class);
                startActivity(intent);
                finish();
            }
        });
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(FaceFailActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        });

    }
}
